"""
@-*- coding: utf-8 -*-
@ python: 3.12.3
@ 创建者: JacksonCode
@ 创建时间: 2025/8/18
"""
import time

from hashlib import md5
import time
import requests
import base64
import json
from Crypto.Util.Padding import pad, unpad

from Crypto.Cipher import AES

# print(time.time())
# 1755494035.9916327
# print(int(time.time()*1000))
# 1755494091983
# 1755493364829

headers = {
    "Accept": "application/json, text/plain, */*",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Cache-Control": "no-cache",
    "Connection": "keep-alive",
    "Content-Type": "application/json;charset=UTF-8",
    "Origin": "https://ggzyfw.fujian.gov.cn",
    "Pragma": "no-cache",
    "Referer": "https://ggzyfw.fujian.gov.cn/business/list",
    "Sec-Fetch-Dest": "empty",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Site": "same-origin",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",
    "portal-sign": "d1cd8e40e7a4f549fbe6618ee0bad055",
    "sec-ch-ua": "\"Not;A=Brand\";v=\"99\", \"Google Chrome\";v=\"139\", \"Chromium\";v=\"139\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\""
}
url = "https://ggzyfw.fujian.gov.cn/FwPortalApi/Trade/TradeInfo"
data = {
    "pageNo": 1,
    "pageSize": 20,
    "total": 0,
    "AREACODE": "",
    "M_PROJECT_TYPE": "",
    "KIND": "GCJS",
    "GGTYPE": "1",
    "PROTYPE": "",
    "timeType": "6",
    "BeginTime": "2025-02-18 00:00:00",
    "EndTime": "2025-08-18 23:59:59",
    "createTime": "",
    "ts": 1755493364829
}
data = json.dumps(data, separators=(',', ':'))
response = requests.post(url, headers=headers, data=data)

# print(type(response.text))
# print(response.json())
# data = response.json().get("Data")
res_data = response.json().get("Data")
# print(res_data)

# 1. base64 解码
base64_encrypt_data = response.json().get("Data")
encrypt_data = base64.b64decode(base64_encrypt_data)
print(f'encrypt_data: {encrypt_data}')

# 2. 解密数据
# (1) 确认key和iv必须保证是16或者24，或者32
key = 'EB444973714E4A40876CE66BE45D5930'.encode()
iv = 'B5A8904209931867'.encode()

# (2) 构建一个aes对象
aes = AES.new(key, AES.MODE_CBC, iv)

# (3) 对数据解密
data = aes.decrypt(encrypt_data)
"""
unpad 是AES-CBC解密后必须的操作，用于移除加密时添加的填充数据，确保还原出原始内容。
它与加密时的 pad() 成对使用，是标准PKCS#7的实现。
"""
data = unpad(data, 16).decode()
print(data)
